package com.qf.service;/*
*王浩政 
*
2022/8/18
9:48
*小米商城
*/

import com.qf.damain.user;
import com.qf.dao.UserDao;
import com.qf.dao.UserDaoImpl;
import com.qf.utils.EmailUtils;
import com.qf.utils.MD5Utils;

public class UserServiceImpl implements UserService{
    private UserDao userDao=new UserDaoImpl();
    @Override
    public boolean checkUserName(String username) {
      user user=  userDao.selectByUserName(username);
      if(user!=null) {
          return true;//用户存在1
      }
        return false;//用户不存在0
    }

    @Override
    public  void regist(user user) {
        //加密码加密
        user.setPassword(MD5Utils.md5(user.getPassword()));
        userDao.insert(user);
        //发送邮件
        EmailUtils.sendEmail(user);
    }

    @Override
    public void active(String email, String code) {
        userDao.updateFlag(email,code);
    }
}
